﻿using System;
using Microsoft.VisualStudio.SharePoint;
using CodeCounsel.SharePoint.DevTools.Commands;
using System.ComponentModel.Composition;
using CodeCounsel.SharePoint.DevTools.ProjectExtensions;
using Microsoft.VisualStudio.SharePoint.Deployment;

namespace CodeCounsel.SharePoint.DevTools.DeploymentSteps
{
    [Export(typeof(IDeploymentStep))]
    [DeploymentStep(DeploymentStepIds.RecreateSite)]
    public class RecreateSite
        : IDeploymentStep
    {
        public void Initialize(IDeploymentStepInfo stepInfo)
        {
            stepInfo.Name = "Recreate site";
            stepInfo.StatusBarMessage = "Recreating site...";
            stepInfo.Description = "Recreates the deployment site";
        }

        public bool CanExecute(IDeploymentContext context)
        {
            return context.Project.SharePointConnection.ExecuteCommand<bool>(CommandIDs.CanCreateSite);
        }

        public void Execute(IDeploymentContext context)
        {
            ProjectProperties properties = context.Project.GetAnnotation<ProjectProperties>();
            context.Project.SharePointConnection.ExecuteCommand<string>(CommandIDs.RecreateSite, properties.SiteDefinition);
        }
    }
}